package com.xpd.spring.demo;

import com.xpd.spring.demo.biz.UserBiz;
import com.xpd.spring.demo.mapper.UserMapper;
import com.xpd.spring.demo.web.UserController;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:bean.xml")
public class Demo {
    @Test
    public void test(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
        Person person = context.getBean(Person.class);
        person.hello();

      Person person1 = (Person) context.getBean("person1");
        Person person2 = (Person) context.getBean("person2");
        person1.hello();
        person2.hello();

        Object person3 = context.getBean("person3");
        Object person4 = context.getBean("person3");
        Object person5 = context.getBean("person3");
        System.out.println(person3==person5);
        System.out.println(person4==person5);
        context.close();
    }
    @Test
    public void test1(){
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AnnoConfig.class);
        Person person = context.getBean(Person.class);
        person.hello();

        Person person1 = (Person) context.getBean("person1");
        Person person2 = (Person) context.getBean("person2");
        person1.hello();
        person2.hello();

        Object person3 = context.getBean("person3");
        Object person4 = context.getBean("person3");
        Object person5 = context.getBean("person3");
        System.out.println(person3==person5);
        System.out.println(person4==person5);
        context.close();
    }
    @Autowired
    @Qualifier("usercontrolAuto")
    UserController userController;
    @Autowired
    UserMapper userMapper;
    @Autowired
    @Qualifier("userbizAuto")
    UserBiz userBiz;
    @Test
    public void test3(){
        System.out.println("userController = " + userController);
        System.out.println("userMapper = " + userMapper);
        System.out.println("userBiz = " + userBiz);
    }
}
